﻿/*******************************************************************************
Copyright (c) 2011-2013, PKStudio

http://pkstudio.org

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*******************************************************************************/

using System;
using System.Diagnostics;

namespace PKEngine
{
	/// <summary>
	/// Configuration of engine. Cannot be modified after game start.
	/// You can set configurations in the Main function in Program.cs.
	/// </summary>
	public class PKConfig
	{
		#region Private Fields
		private bool locked;
		private string gameName;
		private int screenWidth;
		private int screenHeight;
		private float screenScaleX;
		private float screenScaleY;
		private int framePerSecond;
		private PKPixelFormat pixelFormat;
		#endregion

		#region Public Properties
		/// <summary>
		/// Game name.
		/// </summary>
		public string GameName
		{
			get
			{
				return gameName;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				gameName = value;
			}
		}

		/// <summary>
		/// Default screen width.
		/// </summary>
		public int ScreenWidth
		{
			get
			{
				return screenWidth;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				screenWidth = value;
			}
		}

		/// <summary>
		/// Default screen height.
		/// </summary>
		public int ScreenHeight
		{
			get
			{
				return screenHeight;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				screenHeight = value;
			}
		}

		/// <summary>
		/// Default screen scale of x.
		/// </summary>
		public float ScreenScaleX
		{
			get
			{
				return screenScaleX;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				screenScaleX = value;
			}
		}

		/// <summary>
		/// Default screen scale of y.
		/// </summary>
		public float ScreenScaleY
		{
			get
			{
				return screenScaleY;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				screenScaleY = value;
			}
		}

		/// <summary>
		/// Default FPS.
		/// </summary>
		public int FramePerSecond
		{
			get
			{
				return framePerSecond;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				framePerSecond = value;
			}
		}

		/// <summary>
		/// Default pixel format.
		/// </summary>
		public PKPixelFormat PixelFormat
		{
			get
			{
				return pixelFormat;
			}
			set
			{
				Debug.Assert(!locked, "PKConfig: Cannot modify config after game start.");
				pixelFormat = value;
			}
		}
		#endregion

		#region Singleton
		private static PKConfig _sharedConfig;

		public static PKConfig SharedConfig
		{
			get
			{
				if (_sharedConfig == null)
				{
					_sharedConfig = new PKConfig();
				}
				return _sharedConfig;
			}
		}
		#endregion

		#region Initialization
		public PKConfig()
		{
			this.gameName = "PKEngine v0.01";

			this.screenWidth = 320;
			this.screenHeight = 240;
			this.screenScaleX = 2.0f;
			this.screenScaleY = 2.0f;

			this.framePerSecond = 30;

			this.pixelFormat = PKPixelFormat.Argb4444;

			this.locked = false;
		}
		#endregion

		#region Public Methods
		public void Lock()
		{
			this.locked = true;
		}
		#endregion
	}
}
